#include "TypeGenerator.h"

CTypeGenerator::CTypeGenerator(CHeadFile *InContext, const std::vector<std::shared_ptr<CToken>> &Tokens)
{
    Context = InContext;
    this->Tokens = Tokens;

}

void CTypeGenerator::Generate()
{
    std::size_t Index = 0;
    std::size_t ValidSize = Tokens.size();

    //skip static
    {
        auto Token = Tokens[Index];
        if(Token->Type == ETokenType::Static)
        {
            bStatic = true;
            Index++;
        }
    }

    //skip virtual
    {
        auto Token = Tokens[Index];
        if(Token->Type == ETokenType::Virtual)
        {
            bVirtual = true;
            Index++;
        }
    }

    //skip const
    {
        auto Token = Tokens[Index];
        if(Token->Type == ETokenType::Const)
        {
            bConst = true;
            Index++;
        }
    }

    //skip forward declare struct or class
    {
        auto Token = Tokens[Index];
        if(Token->Type == ETokenType::Struct || Token->Type == ETokenType::Class)
        {
            Index++;
        }
    }

    //remove last '&'
    {
        auto Token = Tokens[ValidSize - 1];
        if(Token->Type == ETokenType::And)
        {
            ValidSize--;
        }
    }

    //combine all tokens into one string
    for(std::size_t i = Index; i < ValidSize; i++)
    {
        if(i != Index  && i != ValidSize-1 )
        {
            Result += u8" "; //add a space between tokens , in case of "const int &" -> "constint&"
        }
        Result += Tokens[i]->ToString().ToUtf8();
    }

    for(std::size_t i = 0; i < Tokens.size(); i++)
    {
        if(i != 0 )
        {
            DecoratedResult += u8" "; //add a space between tokens , in case of "const int &" -> "constint&"
        }
        DecoratedResult += Tokens[i]->ToString().ToUtf8();
    }

    
}
